package com.mall.db.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.UmsAdminMapper;
import com.mall.domain.UmsAdmin;
import com.mall.interface1.api.UmsAdminApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UmsAdminApiImpl implements UmsAdminApi {
    @Autowired
    private UmsAdminMapper umsAdminMapper;
    @Override
    public UmsAdmin query(Long userId) {
        return umsAdminMapper.selectById(userId);
    }


    @Override
    public UmsAdmin findByUms(String username, String password) {
        LambdaQueryWrapper<UmsAdmin> qw = new LambdaQueryWrapper<>();
        qw.eq(UmsAdmin::getUsername,username)
                        .eq(UmsAdmin::getPassword,password);
       return umsAdminMapper.selectOne(qw);
    }

    @Override
    public void deleteUser(Integer id) {
        umsAdminMapper.deleteById(id);
    }

    @Override
    public void save(UmsAdmin umsAdmin) {
        umsAdminMapper.insert(umsAdmin);
    }

    @Override
    public void update(UmsAdmin umsAdmin) {
        umsAdminMapper.updateById(umsAdmin);
    }

    @Override
    public UmsAdmin queryUser(String oldPassword, String username) {
        LambdaQueryWrapper<UmsAdmin> wq = new LambdaQueryWrapper<>();
        wq.eq(UmsAdmin::getUsername,username);
        wq.eq(UmsAdmin::getPassword,oldPassword);
        return umsAdminMapper.selectOne(wq);
    }

    @Override
    public IPage<UmsAdmin> listAll(Integer pageNum, Integer pageSize, String keyword) {
        IPage<UmsAdmin> umsAdminPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<UmsAdmin> wq = new LambdaQueryWrapper<>();
        if(keyword!=null&& !keyword.equals("")){
            wq.like(UmsAdmin::getUsername,keyword);
        }
        return umsAdminMapper.selectPage(umsAdminPage, wq);
    }
}
